package com.echo.im.storage.config;

import com.echo.im.common.contant.MQConstants;
import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: echo
 * @time: 2024-08-20
 */
@Configuration
public class RabbitMQConfig {

    @Bean
    public TopicExchange echoStoreExchange() {
        return ExchangeBuilder
                .topicExchange(MQConstants.ECHO_STORE_EXCHANGE)
                .durable(true)
                .build();
    }

    @Bean
    public Queue storePrivateQueue() {
        return new Queue(MQConstants.STORE_PRIVATE_QUEUE);
    }

    @Bean
    public Queue storeGroupQueue() {
        return new Queue(MQConstants.STORE_GROUP_QUEUE);
    }

    @Bean
    public Queue storeSystemQueue() {
        return new Queue(MQConstants.STORE_SYSTEM_QUEUE);
    }


    @Bean
    Binding storePrivateBinding(TopicExchange echoStoreExchange, Queue storePrivateQueue) {
        return BindingBuilder
                .bind(storePrivateQueue)
                .to(echoStoreExchange)
                .with(MQConstants.STORE_PRIVATE_TOPIC);
    }

    @Bean
    Binding storeGroupBinding(TopicExchange echoStoreExchange, Queue storeGroupQueue) {
        return BindingBuilder
                .bind(storeGroupQueue)
                .to(echoStoreExchange)
                .with(MQConstants.STORE_GROUP_TOPIC);
    }

    @Bean
    Binding storeSystemBinding(TopicExchange echoStoreExchange, Queue storeSystemQueue) {
        return BindingBuilder
                .bind(storeSystemQueue)
                .to(echoStoreExchange)
                .with(MQConstants.STORE_SYSTEM_TOPIC);
    }

}
